/**
 * File name:      UserDateLoadService.java
 * Date:           2015-4-19
 * Description:    // 用于详细说明此程序文件完成的主要功
 *                 // 能与其他模块或函数的接口，输出值、
 *                 // 取值范围、含义及参数间的关系
 * Modify History:     Date             Programmer       Notes
 *                    ---------        ---------------  ---------
 *                    2015-4-19            胡少磊                           Initial
 **********************************************************************/
package com.wy.framework.services.login;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.wy.framework.constants.Constants;
import com.wy.framework.dao.ErrorSqlException;
import com.wy.framework.exceptions.ServiceException;
import com.wy.framework.pojos.TSysUserinfo;
import com.wy.framework.services.AbstractBaseService;

/**
 * Created on 2015-4-19
 * <p>
 * Title: [模块名]
 * </p>
 * <p>
 * Description: [描述该类概要功能介绍]
 * </p>
 * 
 * @version 1.0
 */
public class UserDataLoadService extends AbstractBaseService {
    private static Logger logger = LoggerFactory.getLogger(UserDataLoadService.class);

    /**
     * 加载用户权限内的菜单
     */
public List<Map> loadMenuItem(TSysUserinfo userInfo) throws ServiceException {
	try {
	    // 查询用户拥有的功能
	    return this.getDataBaseDao().queryForList("TC_Sys_Function.queryMenuByRoleId", userInfo.getRoleId());
	} catch (Exception e) {
	    logger.error("系统错误:{}", e);
	    // e.printStackTrace();
	    throw new ServiceException(e);
	}
}

    /**
     * 加载用户任务(待办事项) 监管用户: 1.报送截至日期设置 2.待审批数据
     * 
     * 报送数据: 1.未报送数据
     * 
     * 格式: id,type,title,updateTime
     */

public List<Map> loadTaskItem(TSysUserinfo loginUser) throws ServiceException {
	try {
		if(loginUser==null){
			return null;
		}
		List<Map> result = new ArrayList<Map>();
	    StringBuffer sb=new StringBuffer();
	    List params = new ArrayList();
		params.add(loginUser.getUserId());
		List list = this.dataBaseDao.queryForList("tc_sys_userroles.roleId",params);
		String roleId = (String) ((list==null||list.size()==0||list.get(0)==null)?"":((Map)list.get(0)).get("roleId"));
		if(StringUtils.equals(roleId,Constants.ROLE_ADMIN)){
			result = this.dataBaseDao.queryForList("tc_sys_userinfo.something2");
		}else{
			params = new ArrayList();
			params.add(loginUser.getDept());
			params.add(loginUser.getDept());
			params.add(loginUser.getDept());
			params.add(loginUser.getDept());
			result = this.dataBaseDao.queryForList("tc_sys_userinfo.something1", params);
		}
		return result;
	} catch (Exception e) {
		logger.error("系统错误:{}", e);
		throw new ServiceException(e);
	}
}

    /**
     * 加载公告、问卷调查信息 格式: id,type,typeText,title,upateTime
     * 
     * @throws ServiceException
     */
 public List<Map> loadNoticeItem() throws ServiceException {
//	try {
	    //return this.getDataBaseDao().queryForList("TC_Announcement_Questionnaire.getAll");
	    // for(Map noticeMap : noticeList){
	    // String title=noticeMap.get("title").toString();
	    // if(title.length()>17){
	    // noticeMap.put("title", title.substring(0, 17)+"...");
	    // }
	    // }
	     return new ArrayList();
//	} catch (ErrorSqlException e) {
//	    logger.error("系统错误:{}", e);
//	    // e.printStackTrace();
//	    throw new ServiceException(e);
//	}
 }


    /**
     * 查询待审核事项
     */
  private List<Map> getApproveInfo(TSysUserinfo loginUser) throws ErrorSqlException {
	//添加匹配结果记录
	List<Map> result = new ArrayList<Map>();

	return result;
}

    /**
     * 查询待报送事项
     */
	private List<Map> getRptInfo(TSysUserinfo loginUser) throws ErrorSqlException {
		List<Map> result = new ArrayList<Map>();
		return result;
    }

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public List<Map> loadMeetMenu() throws ErrorSqlException {
		String confferenceId = ServletActionContext.getRequest().getParameter("confferenceId");
		List params = new ArrayList();
		params.add(confferenceId);
		return this.getDataBaseDao().queryForList("tb_confference_model.loadMeetMenu", params);
	}
}
